angular.module('Portal', ['ngCookies', 'ui.router', 'angular-jwt', 'angular-md5', 'base64', 'dtrw.bcrypt']);
angular.module('Portal').config(function ($locationProvider, $stateProvider, $urlRouterProvider, $httpProvider,SignSwitch) {

  $httpProvider.interceptors.push('myHttpResponseInterceptor');

  //$urlRouterProvider.otherwise('/');
  $urlRouterProvider.otherwise(function ($injector, $location) {
    var path = $location.path();
    if (path==='/'||path==='/signin') {
      $location.path('/signins');
    } else
      $location.path("/");
  });
  //route for index

  if(SignSwitch.signSwitch){
    $stateProvider
      .state('index', {
        url: '/',
        views: {
          '': {
            templateUrl: 'template/portal/index.html'
            // controller: 'PageController'
          },
          'header@index': {
            templateUrl: 'template/portal/header.html',
            controller: function ($scope, $cookies, jwtHelper, $location) {
                if ($cookies.get("token") !== undefined) {
                  var data = jwtHelper.decodeToken($cookies.get("token"));
                  $scope.username = data.username;
                } else {
                  $scope.username = null;
                }
              $scope.direct2cp = function () {
                window.location.href = "/cp";
              };
              if ($location.path() != "/") {
                jQuery('.navbar-default .navbar-nav.navbar-right > li').removeClass("open");
                jQuery(".navbar-default .navbar-nav.navbar-right > .login").addClass("open");
              }
              jQuery('.navbar-default .navbar-nav.navbar-right > li').click(function () {
                jQuery('.navbar-default .navbar-nav.navbar-right > li').removeClass("open");
                jQuery(this).addClass("open");
              });
              jQuery('.dropdown').mouseover(function () {
                jQuery(this).addClass('mouse');
              });
              jQuery('.dropdown').mouseout(function () {
                // jQuery('.navbar-default .navbar-nav.navbar-right > li').removeClass("open");
                jQuery(this).removeClass('mouse');
              });


            }
          },
          'content@index': {
            templateUrl: 'template/portal/content.html',
            controller: function ($scope, $rootScope) {
              //setIndexHeaderClass();
              $rootScope.$broadcast('MainClassSet', '');

              //for init container height
              $doc_height = jQuery(window).innerHeight();
              jQuery('.full-height .de-video-container').css("height", $doc_height);

              //to set mini windows menu toggle
              jQuery('#menu-btn').toggle(function () {
                jQuery('#mainmenu').show();
                mb = 1;
              }, function () {
                jQuery('#mainmenu').hide();
                mb = 0;
              })
              var x = jQuery(".solution-wear")
              x.moveFilm(x)
              jQuery(document).resize(function () {
                var x = jQuery(".solution-wear")
                x.moveFilm(x)
              })
              jQuery('.carousel').slick({
                autoplay: true,
                dots: true,
                arrows: true
              })
              //compute video size
              //video_autosize();
              //setScrollEvt();
            }
          },
          'main@index': {
            templateUrl: 'template/portal/main.html',
            controller: function ($scope, $rootScope) {
              $rootScope.$on('MainClassSet', function (event, data) {
                $scope.curCls = data;
              });
            }
          },
          'footer@index': {
            templateUrl: 'template/portal/footer.html'
          }
          /*'build@index': {
           templateUrl: 'template/build.html'
           }*/
        }
      })

      .state('index.signin', {
        url: 'signin',
        views: {
          'content@index': {
            templateUrl: 'template/portal/login.html',
            controller: function ($location) {
              if ($location.path() == "/signin") {
                jQuery('.navbar-default .navbar-nav.navbar-right > li').removeClass("open");
                jQuery(".navbar-default .navbar-nav.navbar-right > .login").addClass("open");
              }

            }
          }
        }
      })

      .state('index.about', {
        url: 'about',
        views: {
          'content@index': {
            templateUrl: 'template/portal/about.html'
          }
        }
      })
      .state('index.case', {
        url: 'case',
        views: {
          'content@index': {
            templateUrl: 'template/portal/case.html',
            controller: function ($location) {
              if ($location.path() == "/case") {
                jQuery('.navbar-default .navbar-nav.navbar-right > li').removeClass("open");
                jQuery(".navbar-default .navbar-nav.navbar-right > li").eq(2).addClass("open");
              }

            }
          }
        }
      })
      .state('index.signup', {
        url: 'signup',
        views: {
          'content@index': {
            templateUrl: 'template/portal/reg.html'
          }
        }
      })
      .state('index.container_bigdata', {
        url: 'container_bigdata',
        views: {
          'content@index': {
            templateUrl: 'template/portal/container_bigdata.html'
          }
        }
      })
      .state('index.container_guide', {
        url: 'container_guide',
        views: {
          'content@index': {
            templateUrl: 'template/portal/container_guide.html'
          }
        }
      })
      .state('index.container_enterprise', {
        url: 'container_enterprise',
        views: {
          'content@index': {
            templateUrl: 'template/portal/container_enterprise.html'
          }
        }
      })
      .state('index.container_service', {
        url: 'container_service',
        views: {
          'content@index': {
            templateUrl: 'template/portal/container_service.html'
          }
        }
      })
      //added by Michael
      .state('index.resetpwd', {
        url: 'resetpwd',
        views: {
          'content@index': {
            templateUrl: 'template/portal/resetpwd.html'
          }
        }
      })
      .state('index.updatereg', {
        url: 'updatereg',
        views: {
          'content@index': {
            templateUrl: 'template/portal/updateRegInfo.html'
          }
        }
      })
      .state('index.product', {
        url: 'product',
        views: {
          'content@index': {
            templateUrl: 'template/product/product.html'
          },
          'productitem@index.product': {
            templateUrl: 'template/product/summary.html'
          },
        }
      })
      .state('index.product-ci', {
        url: 'product-ci',
        views: {
          'content@index': {
            templateUrl: 'template/product/product.html',
          },
          'productitem@index.product-ci': {
            templateUrl: 'template/product/ci.html'
          },
        },
        data: {
          item: "全流程"
        }
      })
      .state('index.product-unify', {
        url: 'product-unify',
        views: {
          'content@index': {
            templateUrl: 'template/product/product.html'
          },
          'productitem@index.product-unify': {
            templateUrl: 'template/product/unify.html'
          },
        },
        data: {
          item: "一站式"
        }
      })
      .state('index.product-ecosystem', {
        url: 'product-ecosystem',
        views: {
          'content@index': {
            templateUrl: 'template/product/product.html'
          },
          'productitem@index.product-ecosystem': {
            templateUrl: 'template/product/ecosystem.html'
          },
        },
        data: {
          item: "生态系统"
        }
      })
      .state('index.doc', {
        url: 'doc/:docItem',
        views: {
          'content@index': {
            templateUrl: 'template/doc/doc.html'
          }
        }
      })


  }else{
    $stateProvider
      .state('signins', {
      url: '/signins',
      templateUrl: 'template/portal/logins.html'
      // controller: 'PageController'
    })
      .state('resetpwd', {
        url: '/resetpwd',
        templateUrl: 'template/portal/resetpwd.html'

      })
      .state('signup', {
        url: '/signup',
        templateUrl: 'template/portal/reg.html'

      })

  }


  ;

  $locationProvider.html5Mode(true);
//token Interceptor

  /*  .controller('Controller', function Controller($http) {
   // If localStorage contains the id_token it will be sent in the request
   // Authorization: Bearer [yourToken] will be sent
   $http({
   url: '/sign',
   method: 'GET'
   });
   })*/
});

angular.module('Portal').value("ADMIN", {
  ADMIN_USER: ["library", "system"]
});